//
//  WDLoanHeadView.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/2.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDLoanHeadView.h"

@implementation WDLoanHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
        UIButton *leftBtn = [self setUpBtnWithTitle:@"进件时间 " action:@selector(clickLeftBtn:)];
        
        
        [leftBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.centerY);
            make.left.equalTo(self.left);
            make.width.equalTo(WDScreenW / 2);
        }];
        [leftBtn layoutIfNeeded];
        
        [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -leftBtn.imageView.image.size.width, 0, leftBtn.imageView.image.size.width)];
        [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, leftBtn.titleLabel.bounds.size.width, 0, -leftBtn.titleLabel.bounds.size.width)];
        
        UIButton *rightBtn = [self setUpBtnWithTitle:@"进件状态 " action:@selector(clickRightBtn:)];
        
        [rightBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.centerY);
            make.right.equalTo(self.right);
            make.width.equalTo(WDScreenW / 2);
        }];
        
        [rightBtn layoutIfNeeded];
        
        [rightBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -rightBtn.imageView.image.size.width, 0, rightBtn.imageView.image.size.width)];
        [rightBtn setImageEdgeInsets:UIEdgeInsetsMake(0, rightBtn.titleLabel.bounds.size.width, 0, -rightBtn.titleLabel.bounds.size.width)];
        
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.backgroundColor = WDBackColor;
        [self addSubview:lineLabel];
        
        [lineLabel makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(0);
            make.width.equalTo(self.width);
            make.height.equalTo(1);
        }];
    }
    return self;
}

+ (instancetype)loanHeadView
{
    return [[self alloc] init];
}

- (void)clickLeftBtn:(UIButton *)sender
{
    sender.selected = !sender.selected;
    //WDLog(@"点击了进件时间");
}

- (void)clickRightBtn:(UIButton *)sender
{
    sender.selected = !sender.selected;
    //WDLog(@"点击了进件状态");
}

- (UIButton *)setUpBtnWithTitle:(NSString *)title action:(SEL)action;
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitleColor:WDNavSeleColor forState:UIControlStateSelected];
    
    [btn setImage:[UIImage imageNamed:@"iconfont-fanhui copy 2"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"iconfont-hong"] forState:UIControlStateSelected];
    
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [self addSubview:btn];
    
    return btn;
}

@end
